﻿using System.Collections.Generic;
using System.Linq;

namespace RelationalLinqToSql.Models
{
    public class IranPlacesDataContext
    {
        public static IEnumerable<Province> GetProvinces()
        {
            PlacesDataContext dataContext = new PlacesDataContext();
            return dataContext.Provinces;
        }

        public static Province GetProvince(int provinceID)
        {
            PlacesDataContext dataContext = new PlacesDataContext();
            return dataContext.Provinces.Where
                (province => province.ID == provinceID).Single();
        }

        public static IEnumerable<Place> GetPlaces(int provinceID)
        {
            PlacesDataContext dataContext = new PlacesDataContext();
            return dataContext.Places.Where
                (place => place.ProvinceID == provinceID);
        }

        public static Place GetPlace(int placeID)
        {
            PlacesDataContext dataContext = new PlacesDataContext();
            return dataContext.Places.Where
                (place => place.ID == placeID).Single();
        }
    }
}
